import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
plt.rcParams['font.sans-serif'] = ['SimHei']

# 加载数据
data = pd.read_csv("C:\\Users\\董柳蕙\\Downloads\\heart.csv")

# 排除目标变量
features = data.drop(columns=['target'])

# 创建可视化
for column in features.columns:
    plt.figure(figsize=(8, 6))
    if features[column].dtype == 'object' or len(features[column].unique()) <= 10:  # 类别型变量
        sns.countplot(x=column, data=features, palette='viridis')
        plt.title(f'{column} - 类别分布')
    else:  # 数值型变量
        sns.histplot(features[column], kde=True, color='blue', bins=20)
        plt.title(f'{column} - 数值分布')
    plt.xlabel(column)
    plt.ylabel('频数')
    plt.xticks(rotation=45)
    plt.tight_layout()
    plt.show()
